﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Controls.Animation;

namespace TruckScale.Views
{
  /// <summary>
  /// MainView.xaml 的交互逻辑
  /// </summary>
  public partial class MainView : UserControl
  {
    public MainView()
    {
      InitializeComponent();

      //程序启动初始化加载布局
      using (Stream stream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, "Data/CustomerMainDockLayout.xml"), FileMode.Open))
      {
        stream.Seek(0, SeekOrigin.Begin);
        RootDock.LoadLayout(stream);
      }
      using (Stream stream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, "Data/CustomerRadioDockLayout.xml"), FileMode.Open))
      {
        stream.Seek(0, SeekOrigin.Begin);
        InnerDock.LoadLayout(stream);
      }

      Global._wnd1Handle = RealPlayWnd1.Handle;
      Global._wnd2Handle = RealPlayWnd2.Handle;
      Global._wnd3Handle = RealPlayWnd3.Handle;
      Global._wnd4Handle = RealPlayWnd4.Handle;
      Global._wnd5Handle = RealPlayWnd5.Handle;
      Global._wnd6Handle = RealPlayWnd6.Handle;

      AnimationManager.SetAnimationSelector(this.InnerDock, null);
    }

    //改变字体大小的滚动条
    private void SliderFontSize_Changed(object sender, EventArgs e)
    {
      sliderFontSize.GetBindingExpression(Telerik.Windows.Controls.RadSlider.ValueProperty).UpdateSource();
    }

    //保存当前布局
    private void BtnLayoutSave(object sender, RoutedEventArgs e)
    {
      MemoryStream stream = new MemoryStream();
      RootDock.SaveLayout(stream);
      stream.Seek(0, SeekOrigin.Begin);

      StreamReader reader = new StreamReader(stream);
      File.WriteAllText(System.IO.Path.Combine(Environment.CurrentDirectory, "Data/CustomerMainDockLayout.xml"), reader.ReadToEnd());

      stream = new MemoryStream();
      InnerDock.SaveLayout(stream);
      stream.Seek(0, SeekOrigin.Begin);

      reader = new StreamReader(stream);
      File.WriteAllText(System.IO.Path.Combine(Environment.CurrentDirectory, "Data/CustomerRadioDockLayout.xml"), reader.ReadToEnd());
    }

    //恢复默认布局
    private void BtnLayoutDefault(object sender, RoutedEventArgs e)
    {
      using (Stream stream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, "Data/DefaultMainDockLayout.xml"), FileMode.Open))
      {
        stream.Seek(0, SeekOrigin.Begin);
        RootDock.LoadLayout(stream);
      }
      using (Stream stream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, "Data/DefaultRadioDockLayout.xml"), FileMode.Open))
      {
        stream.Seek(0, SeekOrigin.Begin);
        InnerDock.LoadLayout(stream);
      }
    }
    
  }
}
